#include "mq_connection.hpp"

int main()
{
    //先实例化异步线程池对象
    mymq::AsyncWorker::Ptr pool = std::make_shared<mymq::AsyncWorker>();
    //创建连接对象
    mymq::Connection::Ptr conn = std::make_shared<mymq::Connection>("127.0.0.1",8080,pool);
    //创建信道
    mymq::Channel::Ptr channel = conn->OpenChannel();
    //创建交换机
    google::protobuf::Map<std::string, std::string> map;
    channel->DeclareExchange("exchange1",mymq::ExchangeType::TOPIC,true,false,map);
    //创建队列
    channel->DeclareQueue("queue1",true,false,false,map);
    channel->DeclareQueue("queue2",true,false,false,map);
    //绑定
    channel->QueueBind("exchange1","queue1","queue1");
    channel->QueueBind("exchange1","queue2","news.music.#");
    //循环向队列里发布消息
    for(int i = 0;i<10;i++)
    {
        mymq::BasicProperties bp;
        bp.set_id(mymq::GetUUIDHelper::GetUUID());
        bp.set_delivery(mymq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->BasicPublish("exchange1",&bp,"Hello world-pop-" + std::to_string(i));
    }
        mymq::BasicProperties bp;
        bp.set_id(mymq::GetUUIDHelper::GetUUID());
        bp.set_delivery(mymq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music");
        channel->BasicPublish("exchange1",&bp,"music");
    //关闭信道
    conn->CloseChannel(channel);
    return 0;
}